package chances.epg.ui.widget.taglib;

import java.util.Map;

import javax.servlet.jsp.JspException;

import chances.epg.commons.utils.JSONUtils;
import chances.epg.ui.taglib.html.EpgBodyTagSupport;
import chances.epg.ui.taglib.model.Border;
import chances.epg.ui.taglib.model.Rect;
import chances.epg.ui.taglib.model.Rectable;
import chances.epg.ui.widget.model.WidgetModel;

@SuppressWarnings("serial")
public abstract class WidgetTag extends EpgBodyTagSupport implements Rectable {
	protected Rect rect;
	protected Rect nativeRect;
	private String rectVar;
	private String name;
	private Map<String, Object> opts;
	private String forId;
	private Border paddingRect;
	private Border marginRect;
	private String dataUrl;
	
	public abstract WidgetModel getModel();
	
	public String getNextItemId(){
		return this.getId() +"_" +"item" +"_" +this.getModel().getDatas().size();
	}
	
	public void reset(){};

	@Override
	public int doEndTag() throws JspException {
		int result = super.doEndTag();
		this.reset();
		return result;
	}

	public Rect getRect() {
		return rect;
	}

	public Rect getNativeRect() {
		return nativeRect;
	}

	public String getRectVar() {
		return rectVar;
	}

	public String getName() {
		return name;
	}

	public String getForId() {
		return forId;
	}

	public Border getPaddingRect() {
		return paddingRect;
	}

	public Border getMarginRect() {
		return marginRect;
	}

	public void setRect(Rect rect) {
		this.rect = rect;
	}

	public void setNativeRect(Rect nativeRect) {
		this.nativeRect = nativeRect;
	}

	public void setRectVar(String rectVar) {
		this.rectVar = rectVar;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setOptions(String options) {
		this.opts = JSONUtils.toMap(options);
	}

	public void setForId(String forId) {
		this.forId = forId;
	}

	public void setRectStyle(String value) {
		this.rect = Rect.parseStyle(value);
	}

	public void setPaddingStyle(String value) {
		paddingRect = Border.parseStyle(value);
	}

	public void setMarginStyle(String value) {
		marginRect = Border.parseStyle(value);
	}

	public String getDataUrl() {
		return dataUrl;
	}

	public void setDataUrl(String dataUrl) {
		this.dataUrl = dataUrl;
	}

	public Map<String, Object> getOpts() {
		return opts;
	}

	public void setOpts(Map<String, Object> opts) {
		this.opts = opts;
	}

}
